<template>
	<view class="u-page">
		<view class="content">
			<view class="list-item">
				<uni-forms ref="form" :modelValue="formData" :rules="rules">
						<uni-forms-item  name="content">
					<uni-easyinput type="textarea" :inputBorder="false" v-model="formData.content" placeholder="你想要反馈的信息…" autoHeight="true" />
					</uni-forms-item>
				
				</uni-forms>
				
			</view>
			<view class="submit">
				 <button type="warn" size="default" class="quxiao">取消</button>
				 <button type="warn" size="default" class="postForm" @click="submit()">提交</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pid:'',
				did:'',
				formData:{
					content:'',
				},
				data:{},
				rules:{
					content: {
						rules: [{
									required: true,
									errorMessage: '请输入内容',
								},
								{
									minLength: 2,
									maxLength: 30,
									errorMessage: '内容长度在 {minLength} 到 {maxLength} 个字符',
						}]
					},
				}
			}
		},
		
		methods: {
			
			async submit(){
				await this.$refs.form.validate().then(res=>{
					res.uid = uni.getStorageSync('userData').uid
					this.data = res
					// console.log('data',this.data)
				  	this.postFrom(res)
				}).catch(err =>{
					console.log('表单错误信息：', err);
					uni.showToast({ title: '表单错误信息', icon: 'error', duration: 3000 });
				})
			},
			async postFrom(res){
				
				// res.files = JSON.stringify(this.formData.files)
				const project = await this.GQL({
					"operationName": "createSlSystemFeedback",
					"query": "mutation createSlSystemFeedback($input: CreateSlSystemFeedbackInput!) { createSlSystemFeedback(input: $input) { slSystemFeedback { content id } } }",
					"variables": {"input": {"slSystemFeedback": {"content":res.content,"uid":res.uid}}}
				});
				
				if(project.data.createSlSystemFeedback.slSystemFeedback !=''){
					uni.showToast({ title: '反馈成功', icon: 'success', duration: 3000 });
					uni.reLaunch({
						url:"/pages/user/index"
					});
				}else{
					uni.showToast({ title: '反馈失败', icon: 'error', duration: 3000 });
				}
			}
			
		}
	}
</script>

<style lang="scss">
	.u-page{
		background-color: #FFFFFF;
	}
	.content{
		margin: 0px 15px;
	}
	.list-item{
		padding-top: 15px;
		font-size: 14px;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #767B8D;
		line-height: 24px;
	}
	.submit{
		button: 0;
		padding: 15px;
	
		.quxiao{
			color: #000;
			display: inline-block;
			width: 100px;
			margin-right: 5px;
			background-color: #FFFFFF;
		}
		.postForm{
			display: inline-block;
			width: 150px;
		}
	}
	
</style>
